package cn.zxh.csdn_maven.work.flow.login.chains;

import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;

import cn.zxh.csdn_maven.base.pojo.Cookies;
import cn.zxh.csdn_maven.work.flow.login.AbstractFlowController;

public class JsCookiesFlow extends AbstractFlowController{

	@Override
	public Map<String, Object> execute(HttpClient client, Map<String, Object> params)
			throws ClientProtocolException, IOException {
		Map<String, Object> cookiesMap = new HashMap<String, Object>();
		Map<String, Object> result=new HashMap<String, Object>();
		/**获取时间戳2*/
		String now = System.currentTimeMillis()+"";
		now=now.substring(0,10);
		String dc_session_id="undefined".equals(Cookies.getCookie("dc_session_id"))?new Date().getTime()+"_"+Math.random():Cookies.getCookie("dc_session_id");
		String dc_tos=Integer.toString(Integer.parseInt(now), 36);
		String t=Cookies.getCookie("dc_tos");
		cookiesMap.put("dc_session_id", dc_session_id);
		cookiesMap.put("dc_tos", dc_tos);
		Cookies.setCookies(cookiesMap);
		result.put("msg", "success");
		params.put("tos", Integer.parseInt(now)-Long.parseLong(t, 36));
		params.put("session_id", dc_session_id);
		return result;
	}

	@Override
	public String getBaseUrl() {
		// TODO Auto-generated method stub
		return "https://csdnimg.cn/pubfooter/js/tracking.js?v="+Math.random();
	}

}
